package com.steak.concurrent.Future.futuretask;

import com.steak.concurrent.common.R;

import java.util.concurrent.*;

/**
 * @author 刘牌
 * @Title:
 * @date 2022/3/2615:33
 */
public class Test {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ExecutorService executorService = Executors.newCachedThreadPool();
        FutureTask<R> task1 = new FutureTask<>(new Callable<R>() {
            @Override
            public R call() throws Exception {
                System.out.println("task1");
                return new R(200,"task1",null);
            }
        });

        FutureTask<R> task2 = new FutureTask<>(new Callable<R>() {
            @Override
            public R call() throws Exception {
                System.out.println("task2");
                return new R(200,"task2",null);
            }
        });

        executorService.submit(task1);
        executorService.submit(task2);
        R s = task1.get();
        System.out.println(s);
    }
}
